<template>
    <div>
        <van-nav-bar title="分类" left-text="返回" left-arrow @click-left="() => { $router.push('/') }" />
        <swipe></swipe>
        <van-skeleton title :row="10" v-if="status" />
        <div v-else>
            <van-row>
                <van-col span="6">
                    <van-sidebar v-model="active">
                        <van-sidebar-item v-for="item in categories" :title="item.cat_name" />
                    </van-sidebar>
                </van-col>
                <van-col span="18">
                    <div v-for="item in categories[active]?.children">
                        <h4>{{ item.cat_name }}</h4>
                        <router-link :to="'/goods/' + item.cat_name">
                            <van-grid :column-num="4">
                                <van-grid-item v-for="items in item.children" :icon="items.cat_icon"
                                    :text="items.cat_name" />
                            </van-grid>
                        </router-link>

                    </div>
                </van-col>
            </van-row>
        </div>

    </div>
</template>

<script setup>
import { categoriesApi } from '@/api/api';
import swipe from '@/components/swipe.vue';
import { ref } from 'vue';
let categories = ref([])
categoriesApi().then(res => {
    console.log('分类', res);
    categories.value = res.data.message
    if (res.data.message.length > 0) {
        status.value = false
    }
})
let status = ref(true)
let active = ref(1)
</script>

<style lang="scss" scoped></style>